Conventionally, still image data is often compressed by a method using discrete cosine transform or a method using Wavelet transform. Encoding of this type is variable-length encoding, and hence the code amount changes for each image to be encoded.
According to JPEG encoding as an internal standardization scheme, only one quantization matrix can be defined for an image, and it is difficult to make image data fall within a target code amount without prescan. When JPEG encoding is used in a system which stores data in a limited memory, a memory overflow may occur.
In order to prevent this, conventional schemes used, for example, a method of re-reading a document upon changing the compression ratio parameter when the actual code amount exceeds an expected code amount, or a method of estimating a code amount in advance by prescan and re-setting quantization parameters to adjust the code amount.
As described above, prescan and actual scan are generally executed, but a document must be read at least two times at poor efficiency.
The assignee of the present applicant has proposed a technique of eliminating these two, prescan and actual scan operations and compressing data into a target code amount (e.g., Japanese Patent Laid-Open No. 2003-8903). According to this technique, encoded data is stored in two memories during one image input operation. When a generated code amount reaches a predetermined size, data in one memory is discarded, a parameter for increasing the compression ratio is set, and encoding continues. At this time, encoded data before the compression ratio is increased is stored in the other memory, and re-encoded in accordance with the updated parameter. This process is repeated every time the encoded data amount reaches a predetermined amount.
As a development of the above technique, the present application has also proposed a technique of determining whether area information of an image is, e.g., a character-line image area or halftone area, and switching the quantization matrix in accordance with the determination result in order to reduce degradation of the image quality based on compressed data (e.g., Japanese Patent Laid-Open No. 2003-209698).
According to these references, input of an image can be completed at once, and an encoded data amount generated at the same time can be adjusted to a target value or less.
However, a compression process corresponding to area information of an image does not always provide a high-quality decoded image based on the compression-encoded result. This is because area determination is not always correct. Further, when a normal document deteriorates over time or becomes dirty and loses its contrast, the document may be mistaken as a photo or the like.